<?php
if(!isset($in_pmt)) header("Location:index.php");
?>
<form action="index.php?p=products&amp;action=add" method="post" >
<label form="product">Продукт: </label><input type="text" name="product" />
<input type="submit" value="Добави" />
</form>
<?php
if($_GET["action"]==="add"){
	if($_POST["product"]==""){
		$msg->error("Не сте въвели продукт за добавяне!");
	} else {
		
		$rows = $db->fetch_assoc($db->query("SELECT * FROM products order by pid desc limit 1"));
		//echo $rows["pid"]+1;
		$query = "INSERT INTO products (`pid`,`product`) VALUES ('".($rows["pid"]+1)."','".$_POST["product"]."')";
		$db->query($query);
	}
}
if($_GET["action"]=="update" ){

 $_POST["product"];
	for($i=1;$i<=count($_POST["product"]);$i++){
		$key=explode(":",$_POST["product"][$i-1]);
		//echo $key[0].":".$i.":".$key[2]."<br />";
		$db->query("update products set pid= ".$key[0].",product= '".$key[2]."' where `order` = '".$i."' limit 1");
	
	}
}?>
<form  name="products" method="post" action="index.php?p=products&amp;action=update">
<ul id="products">
<?php
$query = $db->query("SELECT * from products order by `order` asc");
while($row = $db->fetch_assoc($query)){
	$msg->write("<li class=\"ui-state-default\"><span class=\"ui-icon ui-icon-arrowthick-2-n-s\"></span>");
	$msg->write("<a href=\"?p=product&amp;id=".$row["pid"]."\">".$row["product"]."</a><input type=\"hidden\" name=\"product[]\" value=\"".$row["pid"].":".$row["order"].":".$row["product"]."\" /></li>");
}
?>
</ul>
<input type="submit" value="Пренареди" />
</form>